#include <stdlib.h>
#include <stdio.h>
#include <SDL/sdl.h>
#include "sprite.h"
#include "bomb.h"
#include "map.h"
#include "image.h"
#include "sdl_utils.h"


Data Structures | |
| struct | t_unit |
| A unit is a game specific entity, it's attribut vary from one game to an other, but it's use an anim_sprite and got velocity. More... | |
Enumerations | |
| enum | e_actions |
| directions of a unit, and other actions possible More... | |
Functions | |
| void | minsort (unit **tab, size_t size) |
| sort unit tab for z_index order | |
| void | unit_draw (unit *p_unit, SDL_Surface *destination) |
| Draw a unit to the given surface. | |
| void | unit_draw_from_z_index (unit **v_unit, const int unit_nb, SDL_Surface *destination) |
| Draw units to the given surface, sorted by coord_y. A unit with a lower coord_y will be blit first, this avoid that a unit can walk above the head of another unit, it's a purly cosmetic function. | |
| void | unit_update (unit *p_unit, map *p_map) |
| Call updates functions (check wall, bombs, etc). | |
| void | unit_update_frame (unit *p_unit) |
| Update the frame of the unit, call anim_sprite_update_frame when a move is detected by checking the velocity. | |
| void | unit_update_position (unit *p_unit) |
| Update the unit coords according to it's velocity. | |
| struct bomb_t * | unit_put_bomb (unit *p_unit, map *p_map) |
| Put a bomb to the map. | |
| int | unit_y_compare (void const *a, void const *b) |
| Compare the z_index of units. | |
| void | unit_set_vel_x (unit *p_unit, int value) |
| Set the x velocity of a unit. | |
| void | unit_set_vel_y (unit *p_unit, int value) |
| Set the y velocity of a unit. | |
| int | unit_get_x (unit *p_unit) |
| Get the x coord of the unit. | |
| int | unit_get_y (unit *p_unit) |
| Get the y coord of the unit. | |
| int | unit_get_index_x (unit *p_unit) |
| Get the x index of the unit. | |
| int | unit_get_index_y (unit *p_unit) |
| Get the y index of the unit. | |
| void | unit_check_tile (unit *p_unit, map *p_map) |
| Check if the unit can move on tiles (is_walckable ? ). | |
| void | unit_check_bomb (unit *p_unit, map *p_map) |
| Check if the unit can move on a bomb. | |
| SDL_Rect | unit_get_bounding_box (unit *p_unit) |
| Get the bounding box of a unit. | |
| int | unit_get_bounding_center_x (unit *p_unit) |
| Get the x coord of the center of the bounding box. | |
| int | unit_get_bounding_center_y (unit *p_unit) |
| Get the y coord of the center of the bounding box. | |
| int | unit_get_bounding_index_center_x (unit *p_unit) |
| Get the x coord of the center of the bounding box. | |
| int | unit_get_bounding_index_center_y (unit *p_unit) |
| Get the y coord of the center of the bounding box. | |
| void | unit_tile_protect (unit *p_unit, map *p_map, int direction) |
| Set flag protected in the map around a unit, no block can be placed in a protected tile, in order to allow a unit to move at the begining of the battle. The tile protection must make a corner or a line longeur than the unit fire power. | |
| int | unit_check_victory (unit **v_unit, int unit_nb) |
| Check if a unit in the array is vicrorious (i.e. the only not dead). | |
| void | unit_init (unit **v_unit, int unit_nb) |
| Give to unit a lot of hard coded values (animation key, key binding, speed, bomb left...) Theses values will be soon in a file to load and save theme, but I did make any editor yet... | |
| enum e_actions |
directions of a unit, and other actions possible
| NO_WAY_OUT | When the unit cannot move to another tile, other are self explanitory |
Check if the unit can move on a bomb.
Algo unit_check_bomb Begin If the unit velocity is <= 1 // Moving to the left If the Center of the unit index at x is differant of the Index from the x left side of the bounding box AND If the map tile at the left side index of the bounding box is a bomb Then Go to previous position (move is not allowed) End If End
The same goes for other directions, the side and the previous position changed. Remember that x and y coord are given from the left top side, for check when the unit move down or right, the height or the width of the bounding box must be added (see source for more info). Use a pice of paper, draw the map and the unit bounding box with a dot at his center, follow the pseudo code and you will understand how it works.
Check if the unit can move on tiles (is_walckable ? ).
| int unit_check_victory | ( | unit ** | v_unit, | |
| int | unit_nb | |||
| ) |
Check if a unit in the array is vicrorious (i.e. the only not dead).
| void unit_draw | ( | unit * | p_unit, | |
| SDL_Surface * | destination | |||
| ) |
Draw a unit to the given surface.
| Unit | to draw | |
| Surface | where draw |
| void unit_draw_from_z_index | ( | unit ** | v_unit, | |
| const int | unit_nb, | |||
| SDL_Surface * | destination | |||
| ) |
Draw units to the given surface, sorted by coord_y. A unit with a lower coord_y will be blit first, this avoid that a unit can walk above the head of another unit, it's a purly cosmetic function.
| Units | to draw | |
| Number | of units in the array | |
| Surface | where draw |
| SDL_Rect unit_get_bounding_box | ( | unit * | p_unit | ) |
Get the bounding box of a unit.
| The | unit |
| int unit_get_bounding_center_x | ( | unit * | p_unit | ) |
Get the x coord of the center of the bounding box.
| Unit | holding the bounding box |
| int unit_get_bounding_center_y | ( | unit * | p_unit | ) |
Get the y coord of the center of the bounding box.
| Unit | holding the bounding box |
| int unit_get_bounding_index_center_x | ( | unit * | p_unit | ) |
Get the x coord of the center of the bounding box.
| Unit | holding the bounding box |
| int unit_get_bounding_index_center_y | ( | unit * | p_unit | ) |
Get the y coord of the center of the bounding box.
| Unit | holding the bounding box |
| int unit_get_index_x | ( | unit * | p_unit | ) |
Get the x index of the unit.
| int unit_get_index_y | ( | unit * | p_unit | ) |
Get the y index of the unit.
Put a bomb to the map.
| void unit_set_vel_x | ( | unit * | p_unit, | |
| int | value | |||
| ) |
Set the x velocity of a unit.
| unit | to change the velocity | |
| New | velocity |
| void unit_set_vel_y | ( | unit * | p_unit, | |
| int | value | |||
| ) |
Set the y velocity of a unit.
| Unit | to change the velocity | |
| New | velocity |
Set flag protected in the map around a unit, no block can be placed in a protected tile, in order to allow a unit to move at the begining of the battle. The tile protection must make a corner or a line longeur than the unit fire power.
| Direction | to protect |
| void unit_update_position | ( | unit * | p_unit | ) |
Update the unit coords according to it's velocity.
| Unit | to update |
| int unit_y_compare | ( | void const * | a, | |
| void const * | b | |||
| ) |
Compare the z_index of units.
1.5.4